package com.hancheng.goodscloud.business.controller;

import com.hancheng.commoncloud.business.entity.dto.IdDTO;
import com.hancheng.commoncloud.business.entity.dto.IdListDTO;
import com.hancheng.commoncloud.framework.result.PageResult;
import com.hancheng.commoncloud.framework.result.Response;
import com.hancheng.goodscloud.business.entity.dto.GoodsDTO;
import com.hancheng.goodscloud.business.entity.dto.GoodsInsertDTO;
import com.hancheng.goodscloud.business.entity.dto.GoodsUpdateDTO;
import com.hancheng.goodscloud.business.entity.vo.GoodsVO;
import com.hancheng.goodscloud.business.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* 商品表 Controller
*
* @author 韩诚
* @date 2025/06/22
*/
@Api(tags = "商品表")
@RestController
@RequestMapping("/api/goods")
public class GoodsController {

    @Autowired
	private GoodsService goodsService;

    /**
    * 分页列表
     *
    *
    * @param goodsDTO
    * @return
    */
    @ApiOperation(value = "分页列表", httpMethod = "POST")
    @PostMapping("/getPageList")
    public Response<PageResult<GoodsVO>> getPageList(@RequestBody GoodsDTO goodsDTO) {
        return Response.ok(goodsService.getPageList(goodsDTO));
    }

    /**
    * 下拉框列表
    *
    * @param goodsDTO
    * @return
    */
    @ApiOperation(value = "下拉框列表", httpMethod = "POST")
    @PostMapping("/getList")
    public Response<List<GoodsVO>> getList(@RequestBody GoodsDTO goodsDTO) {
        return Response.ok(goodsService.getList(goodsDTO));
    }

    /**
    * 明细
    *
    * @param idDTO
    * @return
    */
    @ApiOperation(value = "明细", httpMethod = "POST")
    @PostMapping("/detail")
    public Response<GoodsVO> detail(@RequestBody @Valid IdDTO idDTO) {
        return Response.ok(goodsService.detail(idDTO));
    }

    /**
    * 新增
    *
    * @param goodsInsertDTO
    * @return
    */
    @ApiOperation(value = "新增", httpMethod = "POST")
    @PostMapping("/insert")
    public Response<Void> insert(@RequestBody @Valid GoodsInsertDTO goodsInsertDTO) {
        goodsService.insert(goodsInsertDTO);
        return Response.ok();
    }

    /**
    * 修改
    *
    * @param goodsUpdateDTO
    * @return
    */
    @ApiOperation(value = "修改", httpMethod = "POST")
    @PostMapping("/update")
    public Response<Void> update(@RequestBody @Valid GoodsUpdateDTO goodsUpdateDTO) {
        goodsService.update(goodsUpdateDTO);
        return Response.ok();
    }

    /**
    * 批量删除
    *
    * @param idListDTO
    * @return
    */
    @ApiOperation(value = "批量删除", httpMethod = "POST")
    @PostMapping("/deleteBatch")
    public Response<Void> deleteBatch(@RequestBody @Valid IdListDTO idListDTO) {
        goodsService.deleteBatch(idListDTO);
        return Response.ok();
    }

}
